/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 解析.node.node;

import 解析.Matcher;

/**
 *
 * @author yanxi
 */
public class Caret extends Node {

    @Override
    public boolean match(Matcher matcher, int i, CharSequence seq) {
        int startIndex = matcher.from;
        int endIndex = matcher.to;
        if (!matcher.anchoringBounds) {
            startIndex = 0;
            endIndex = matcher.getTextLength();
        }
        // Perl does not match ^ at end of input even after newline
        if (i == endIndex) {
            matcher.hitEnd = true;
            return false;
        }
        if (i > startIndex) {
            char ch = seq.charAt(i - 1);
            if (ch != '\n' && ch != '\r' && (ch | 1) != '\u2029' && ch != '\u0085') {
                return false;
            }
            // Should treat /r/n as one newline
            if (ch == '\r' && seq.charAt(i) == '\n') {
                return false;
            }
        }
        return next.match(matcher, i, seq);
    }
}
